﻿
namespace bookMaster.AssetSystem.Windows.Forms
{
	/// <summary>
	/// abstract HistoricoPedidos typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class HistoricoPedidosDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<HistoricoPedidosDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.HistoricoPedidos _currentHistoricoPedidos = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxHistoricoPedidosDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxHistoricoPedidosErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxHistoricoPedidosBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the IdHistorico property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIdHistoricoDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the IdPedido property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIdPedidoDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the IdCliente property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIdClienteDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the FechaPedido property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxFechaPedidoDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the EstadoPedido property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxEstadoPedidoDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.HistoricoPedidos> _HistoricoPedidosList;
				
		/// <summary> 
		/// The list of HistoricoPedidos to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.HistoricoPedidos> HistoricoPedidosList
		{
			get {return this._HistoricoPedidosList;}
			set
			{
				this._HistoricoPedidosList = value;
				this.uxHistoricoPedidosBindingSource.DataSource = null;
				this.uxHistoricoPedidosBindingSource.DataSource = value;
				this.uxHistoricoPedidosDataGridView.DataSource = null;
				this.uxHistoricoPedidosDataGridView.DataSource = this.uxHistoricoPedidosBindingSource;				
				//this.uxHistoricoPedidosBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxHistoricoPedidosBindingSource_ListChanged);
				this.uxHistoricoPedidosBindingSource.CurrentItemChanged += new System.EventHandler(OnHistoricoPedidosBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnHistoricoPedidosBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentHistoricoPedidos = uxHistoricoPedidosBindingSource.Current as Entities.HistoricoPedidos;
			
			if (_currentHistoricoPedidos != null)
			{
				_currentHistoricoPedidos.Validate();
			}
			//_HistoricoPedidos.Validate();
			OnCurrentEntityChanged();
		}

		//void uxHistoricoPedidosBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.HistoricoPedidos"/> instance.
		/// </summary>
		public Entities.HistoricoPedidos SelectedHistoricoPedidos
		{
			get {return this._currentHistoricoPedidos;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxHistoricoPedidosDataGridView.VirtualMode;}
			set
			{
				this.uxHistoricoPedidosDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxHistoricoPedidosDataGridView.AllowUserToAddRows;}
			set {this.uxHistoricoPedidosDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxHistoricoPedidosDataGridView.AllowUserToDeleteRows;}
			set {this.uxHistoricoPedidosDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxHistoricoPedidosDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxHistoricoPedidosDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="HistoricoPedidosDataGridViewBase"/> class.
		/// </summary>
		public HistoricoPedidosDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxHistoricoPedidosDataGridView = new System.Windows.Forms.DataGridView();
			this.uxHistoricoPedidosBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxHistoricoPedidosErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIdHistoricoDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxIdPedidoDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxIdClienteDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxFechaPedidoDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxEstadoPedidoDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxHistoricoPedidosDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxHistoricoPedidosBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxHistoricoPedidosErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxHistoricoPedidosErrorProvider
			// 
			this.uxHistoricoPedidosErrorProvider.ContainerControl = this;
			this.uxHistoricoPedidosErrorProvider.DataSource = this.uxHistoricoPedidosBindingSource;						
			// 
			// uxHistoricoPedidosDataGridView
			// 
			this.uxHistoricoPedidosDataGridView.AutoGenerateColumns = false;
			this.uxHistoricoPedidosDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxHistoricoPedidosDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIdHistoricoDataGridViewColumn,
		this.uxIdPedidoDataGridViewColumn,
		this.uxIdClienteDataGridViewColumn,
		this.uxFechaPedidoDataGridViewColumn,
		this.uxEstadoPedidoDataGridViewColumn			});
			this.uxHistoricoPedidosDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxHistoricoPedidosDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxHistoricoPedidosDataGridView.Name = "uxHistoricoPedidosDataGridView";
			this.uxHistoricoPedidosDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxHistoricoPedidosDataGridView.TabIndex = 0;	
			this.uxHistoricoPedidosDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxHistoricoPedidosDataGridView.EnableHeadersVisualStyles = false;
			this.uxHistoricoPedidosDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnHistoricoPedidosDataGridViewDataError);
			this.uxHistoricoPedidosDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnHistoricoPedidosDataGridViewCellValueNeeded);
			this.uxHistoricoPedidosDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnHistoricoPedidosDataGridViewCellValuePushed);
			
			//
			// uxIdHistoricoDataGridViewColumn
			//
			this.uxIdHistoricoDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIdHistoricoDataGridViewColumn.DataPropertyName = "IdHistorico";
			this.uxIdHistoricoDataGridViewColumn.HeaderText = "IdHistorico";
			this.uxIdHistoricoDataGridViewColumn.Name = "uxIdHistoricoDataGridViewColumn";
			this.uxIdHistoricoDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIdHistoricoDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIdHistoricoDataGridViewColumn.ReadOnly = true;		
			//
			// uxIdPedidoDataGridViewColumn
			//
			this.uxIdPedidoDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIdPedidoDataGridViewColumn.DataPropertyName = "IdPedido";
			this.uxIdPedidoDataGridViewColumn.HeaderText = "IdPedido";
			this.uxIdPedidoDataGridViewColumn.Name = "uxIdPedidoDataGridViewColumn";
			this.uxIdPedidoDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIdPedidoDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIdPedidoDataGridViewColumn.ReadOnly = false;		
			//
			// uxIdClienteDataGridViewColumn
			//
			this.uxIdClienteDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIdClienteDataGridViewColumn.DataPropertyName = "IdCliente";
			this.uxIdClienteDataGridViewColumn.HeaderText = "IdCliente";
			this.uxIdClienteDataGridViewColumn.Name = "uxIdClienteDataGridViewColumn";
			this.uxIdClienteDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIdClienteDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIdClienteDataGridViewColumn.ReadOnly = false;		
			//
			// uxFechaPedidoDataGridViewColumn
			//
			this.uxFechaPedidoDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxFechaPedidoDataGridViewColumn.DataPropertyName = "FechaPedido";
			this.uxFechaPedidoDataGridViewColumn.HeaderText = "FechaPedido";
			this.uxFechaPedidoDataGridViewColumn.Name = "uxFechaPedidoDataGridViewColumn";
			this.uxFechaPedidoDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxFechaPedidoDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxFechaPedidoDataGridViewColumn.ReadOnly = false;		
			//
			// uxEstadoPedidoDataGridViewColumn
			//
			this.uxEstadoPedidoDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxEstadoPedidoDataGridViewColumn.DataPropertyName = "EstadoPedido";
			this.uxEstadoPedidoDataGridViewColumn.HeaderText = "EstadoPedido";
			this.uxEstadoPedidoDataGridViewColumn.Name = "uxEstadoPedidoDataGridViewColumn";
			this.uxEstadoPedidoDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxEstadoPedidoDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxEstadoPedidoDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxHistoricoPedidosDataGridView);
			this.Name = "HistoricoPedidosDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxHistoricoPedidosErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxHistoricoPedidosDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxHistoricoPedidosBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				HistoricoPedidosDataGridViewEventArgs args = new HistoricoPedidosDataGridViewEventArgs();
				args.HistoricoPedidos = _currentHistoricoPedidos;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class HistoricoPedidosDataGridViewEventArgs : System.EventArgs
		{
			private Entities.HistoricoPedidos	_HistoricoPedidos;
	
			/// <summary>
			/// the  Entities.HistoricoPedidos instance.
			/// </summary>
			public Entities.HistoricoPedidos HistoricoPedidos
			{
				get { return _HistoricoPedidos; }
				set { _HistoricoPedidos = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxHistoricoPedidosDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnHistoricoPedidosDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxHistoricoPedidosDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnHistoricoPedidosDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxHistoricoPedidosDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIdHistoricoDataGridViewColumn":
						e.Value = HistoricoPedidosList[e.RowIndex].IdHistorico;
						break;
					case "uxIdPedidoDataGridViewColumn":
						e.Value = HistoricoPedidosList[e.RowIndex].IdPedido;
						break;
					case "uxIdClienteDataGridViewColumn":
						e.Value = HistoricoPedidosList[e.RowIndex].IdCliente;
						break;
					case "uxFechaPedidoDataGridViewColumn":
						e.Value = HistoricoPedidosList[e.RowIndex].FechaPedido;
						break;
					case "uxEstadoPedidoDataGridViewColumn":
						e.Value = HistoricoPedidosList[e.RowIndex].EstadoPedido;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxHistoricoPedidosDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnHistoricoPedidosDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxHistoricoPedidosDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIdHistoricoDataGridViewColumn":
						HistoricoPedidosList[e.RowIndex].IdHistorico = (System.Int32)e.Value;
						break;
					case "uxIdPedidoDataGridViewColumn":
						HistoricoPedidosList[e.RowIndex].IdPedido = (System.Int32?)e.Value;
						break;
					case "uxIdClienteDataGridViewColumn":
						HistoricoPedidosList[e.RowIndex].IdCliente = (System.Int32?)e.Value;
						break;
					case "uxFechaPedidoDataGridViewColumn":
						HistoricoPedidosList[e.RowIndex].FechaPedido = (System.DateTime?)e.Value;
						break;
					case "uxEstadoPedidoDataGridViewColumn":
						HistoricoPedidosList[e.RowIndex].EstadoPedido = (System.Int32?)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
